﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Test_Drag_N_drop
{
    class Button
    {

        protected Texture2D _texture;

        protected Rectangle rectangle;
        protected SpriteFont myFont;
        public Rectangle Rect
        {
            get { return rectangle; }
            set { rectangle = value; }
        }

        private bool over = false;

        protected Texture2D textureIdle;
        protected Texture2D textureOver;
        protected Texture2D text;

        public Texture2D Texture
        {
            get { return _texture; }
            set { _texture = value; }
        }


        public Button()
        {
        }

        public void Initialize(int x, int y)
        {
            rectangle = new Rectangle(x, y, 0, 0);
        }

        public virtual  void LoadContent(ContentManager content)
        {
            textureIdle = content.Load<Texture2D>("Idle");
            textureOver = content.Load<Texture2D>("Over");
            _texture = textureIdle;
            myFont = content.Load<SpriteFont>("FontBlock");
            rectangle.X = rectangle.X - _texture.Width / 2;
            rectangle.Y = rectangle.Y - _texture.Height / 2;
            rectangle.Width = _texture.Width;
            rectangle.Height = _texture.Height;

        }


        public void Update(GameTime gameTime, MouseState ms, MouseState pms)
        {
            if (rectangle.Contains(ms.X, ms.Y))
            {
                over = true;
                if (ms.LeftButton == ButtonState.Pressed)
                {
                    if (pms.LeftButton == ButtonState.Released)
                    {
                        doAction(ms.X, ms.Y);
                    }
                }
                else
                {
                }
            }
            else
            {
                over = false;
            }

            if (over)
            {
                _texture = textureOver;
            }
            else
            {
                _texture = textureIdle;
            }
        }

        public virtual void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
        }

        protected virtual void doAction(int mX, int mY)
        {
        }
    }
}
